<?php
class ModelExtensionLogisticsMethod extends Model {
	public function addLogisticsMethod($data) {
		$this->event->trigger('pre.admin.logistics_method.add', $data);

		$this->db->query("INSERT INTO " . DB_PREFIX . "logistics_method SET  code = '" . $this->db->escape($data['logistics_method_code']) . "', name ='" . $this->db->escape($data['logistics_method_name']) . "', date_add = NOW()");

		$logistics_method_id = $this->db->getLastId();
		$this->event->trigger('post.admin.logistics_method.add', $logistics_method_id);

		return $logistics_method_id;
	}

	public function editLogisticsMethod($logistics_method_id, $data) {
		$this->event->trigger('pre.admin.logistics_method.edit', $data);

		$this->db->query("UPDATE " . DB_PREFIX . "logistics_method SET code = '" . $this->db->escape($data['logistics_method_code']) . "', name ='" . $this->db->escape($data['logistics_method_name']) . "' WHERE logistics_method_id = '" . (int)$logistics_method_id . "'");

		$this->event->trigger('post.admin.category.delete', $logistics_method_id);
	}



	public function getLogisticsMethod($logistics_method_id) {
		$query = $this->db->query("SELECT * FROM " . DB_PREFIX . "logistics_method where logistics_method_id='".(int)$logistics_method_id."'");

		return $query->row;
	}

	public function getLogisticsMethods($data = array()) {
		$sql = "SELECT *  FROM " . DB_PREFIX . "logistics_method order by date_add asc";

		if (isset($data['start']) || isset($data['limit'])) {
			if ($data['start'] < 0) {
				$data['start'] = 0;
			}

			if ($data['limit'] < 1) {
				$data['limit'] = 20;
			}

			$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
		}

		$query = $this->db->query($sql);

		return $query->rows;
	}

	public function  getTotalLogisticsMethods(){
	    $sql = "SELECT count(*) as total  FROM " . DB_PREFIX . "logistics_method order by date_add asc";


	    $query = $this->db->query($sql);

	    return $query->row['total'];

	}

	public function deleteLogisticsMethod($logistics_method_id){

	    $sql = "Delete  FROM " . DB_PREFIX . "logistics_method where logistics_method_id='".(int)$logistics_method_id."'";


	    $query = $this->db->query($sql);
	}

}
